function onPreview(event) {
    const {urls, current} = event.currentTarget.dataset
    wx.previewImage({
        urls,
        current
    })
}

function onCall(phoneNumber) {
    wx.makePhoneCall({
        phoneNumber
    })
}

function onInput(event, callee, bindField = 'info') {
    const {field} = event.currentTarget.dataset
    const value = event.detail.value ? event.detail.value : event.detail
    if (bindField) {
        callee.setData({
            [`${bindField}.${field}`]: value
        })
    } else {
        callee.setData({
            [field]: value
        })
    }
}

function onPageScrollForNavBar(event, callee, field = 'isTop') {
    const isTop = callee.data[field]
    const top = event.scrollTop
    if (top === 0 && !isTop) {
        callee.setData({[field]: true})
    }
    if (top !== 0 && isTop) {
        callee.setData({[field]: false})
    }
}

export {
    onPreview,
    onCall,
    onInput,
    onPageScrollForNavBar
}
